package second50;

public class T0069 {
    public int mySqrt(int x) {
        if (x == 0) return 0;
        int r = (int) Math.exp(0.5 * Math.log(x));
        return (r + 1) * (r + 1) <= x ? r + 1 : r;
    }

    public int mySqrt2(int x) {
        if (x == 0) return 0;
        int left = 1, right = x;
        int ans = -1;
        while (left <= right) {
            int mod = left + (right - left) / 2;
            if ((long)mod * mod <= x) {
                ans = mod;
                left = mod + 1;
            } else {
                right = mod - 1;
            }
        }
        return ans;
    }

}
